package com.lzhl.imaging.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author 李柱良(@柱子的日月)
 * @date 2014/8/27
 */
public class MainUI extends JFrame {

    public MainUI() {
        super("光圈，焦距和摄距对景深的影响");

        JPanel container = (JPanel) getContentPane();
        container.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        container.setLayout(new BorderLayout());

        JToolBar toolBar = new JToolBar();
        toolBar.setRollover(true);
        container.add(toolBar, BorderLayout.NORTH);

        JButton btnTheory = new JButton("原理");
        toolBar.add(btnTheory);
        JButton btnAbout = new JButton("关于");
        toolBar.add(btnAbout);
        JButton btnExit = new JButton("退出");
        toolBar.add(btnExit);

        container.add(new ImagingUI(), BorderLayout.CENTER);

        btnTheory.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showTheory();
            }
        });
        btnAbout.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showAbout();
            }
        });
        btnExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });


        setSize(1024, 768);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public void showTheory() {
        new TheoryUI(this);
    }

    public void showAbout() {
        new AboutUI(this);
    }
}
